﻿namespace Away.IdentityServer.Core.Api;

public static class ClientApi
{
    /// <summary>
    /// 客户端管理接口
    /// </summary>
    public static IEndpointRouteBuilder MapClientApi(this IEndpointRouteBuilder endpoint)
    {
        endpoint.MapGet("/client", Page);
        endpoint.MapPost("/client", Save);
        endpoint.MapDelete("/client", Remove);
        return endpoint;
    }

    /// <summary>
    /// 获取客户端分页列表
    /// </summary>
    private static IResult Page([AsParameters] ClientSearch search, IClientService service)
    {
        return service.Page(search);
    }

    /// <summary>
    /// 添加、编辑客户端
    /// </summary>   
    private static IResult Save([FromBody] Client model, IClientService service)
    {
        service.Save(model);
        return ApiResult.Ok();
    }

    /// <summary>
    /// 删除客户端
    /// </summary>
    private static IResult Remove([FromBody] List<int> ids, IClientService service)
    {
        service.Remove(ids);
        return ApiResult.Ok();
    }
}